﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CLUBsInterpreter.AST;

namespace CLUBsInterpreter.ObjectTypes
{
	/**
	 * <summary>
	 * Describes an integer object in the CLUBs environment.
	 * </summary>
	 **/
	class CLUBsInteger : CLUBsObject
	{
		/**
		 * <summary>
		 * The actual value of the integer object.
		 * </summary>
		 **/
		public int InternalInteger;

		// CONSTRUCTORS
		/**
		 * <summary>
		 * Default constructor creates 0 integer.
		 * </summary>
		 **/
		public CLUBsInteger()
		{
			// Set the object identifier type
			ObjectIdentifierType = AST.IdentifierType.Integer;
		}
		/**
		 * <summary>
		 * Constructor taking initial value.
		 * </summary>
		 **/
		public CLUBsInteger(int i)
			: this()
		{
			// Set internal integer to specified initial value
			InternalInteger = i;
		}

		/**
		 * <see cref="CLUBsObject.CopyValueFromObject"/>
		 **/
		public override void CopyValueFromObject(CLUBsObject obj)
		{
			// Cast the incoming object to a CLUBsInteger
			CLUBsInteger intObj = (CLUBsInteger)obj;
			// Set our internal integer to the same value as the one in the object to be copied
			InternalInteger = intObj.InternalInteger;
		}

		public override string ToString()
		{
			return InternalInteger.ToString();
		}

		// CASTING OPERATORS

		/**
		 * <summary>
		 * Implicit casting operator for easy cast from native C# int.
		 * </summary>
		 **/
		public static implicit operator CLUBsInteger(int i)
		{
			// Return new CLUBsInteger object with the same value as the int
			return new CLUBsInteger(i);
		}

		/**
		 * <summary>
		 * Implicit casting operator for easy cast to native C# int.
		 * </summary>
		 **/
		public static implicit operator int(CLUBsInteger ci)
		{
			// Return the internal int
			return ci.InternalInteger;
		}

		/**
		 * <summary>
		 * + arithmetic operator for CLUBsIntegers.
		 * </summary>
		 **/
		public static CLUBsInteger operator +(CLUBsInteger obj1, CLUBsInteger obj2)
		{
			// Return the resulting added integer
			// (Note that the resulting native int is being implicitly casted to a CLUBsInteger due to the return type!)
			return obj1.InternalInteger + obj2.InternalInteger;
		}
		/**
		 * <summary>
		 * - arithmetic operator for CLUBsIntegers.
		 * </summary>
		 **/
		public static CLUBsInteger operator -(CLUBsInteger obj1, CLUBsInteger obj2)
		{
			// Return the resulting subtracted integer
			// (Note that the resulting native int is being implicitly casted to a CLUBsInteger due to the return type!)
			return obj1.InternalInteger - obj2.InternalInteger;
		}
		/**
		 * <summary>
		 * * arithmetic operator for CLUBsIntegers.
		 * </summary>
		 **/
		public static CLUBsInteger operator *(CLUBsInteger obj1, CLUBsInteger obj2)
		{
			// Return the resulting multiplied integer
			// (Note that the resulting native int is being implicitly casted to a CLUBsInteger due to the return type!)
			return obj1.InternalInteger * obj2.InternalInteger;
		}
		/**
		 * <summary>
		 * / arithmetic operator for CLUBsIntegers.
		 * </summary>
		 **/
		public static CLUBsInteger operator /(CLUBsInteger obj1, CLUBsInteger obj2)
		{
			// Return the resulting divided integer
			// (Note that the resulting native int is being implicitly casted to a CLUBsInteger due to the return type!)
			return obj1.InternalInteger / obj2.InternalInteger;
		}
	}
}
